/*
 * @Author: your name
 * @Date: 2020-11-22 15:28:22
 * @LastEditTime: 2020-12-08 21:10:09
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \wechat-server\src\routes\weibo\hotItem.js
 */

import Router from "koa-router";
import axios from "axios";

const router = Router();

router.get("/zhihu/question/:id/:offset", async (ctx, next) => {
  let id = ctx.params["id"];
  let offset = ctx.params["offset"];
  let headers = {
    "User-Agent":
      "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36",
    "Accept-Language": "en-US,en;q=0.5",
    "WeiboData-Type": "application/x-www-form-urlencoded",
    Connection: "Keep-Alive",
  };
  let data = await axios
    .get(
      `https://www.zhihu.com/api/v4/questions/${id}/answers?include=data%5B*%5D.is_normal%2Cadmin_closed_comment%2Creward_info%2Cis_collapsed%2Cannotation_action%2Cannotation_detail%2Ccollapse_reason%2Cis_sticky%2Ccollapsed_by%2Csuggest_edit%2Ccomment_count%2Ccan_comment%2Ccontent%2Ceditable_content%2Cvoteup_count%2Creshipment_settings%2Ccomment_permission%2Ccreated_time%2Cupdated_time%2Creview_info%2Crelevant_info%2Cquestion%2Cexcerpt%2Crelationship.is_authorized%2Cis_author%2Cvoting%2Cis_thanked%2Cis_nothelp%2Cis_labeled%2Cis_recognized%2Cpaid_info%2Cpaid_info_content%3Bdata%5B*%5D.mark_infos%5B*%5D.url%3Bdata%5B*%5D.author.follower_count%2Cbadge%5B*%5D.topics&offset=${offset}&limit=5&sort_by=default&platform=desktop`,
      {
        headers: headers,
      }
    )
    .then((res) => {
      return res.data.data;
    })
    .catch((err) => {
      console.log("获取知乎回答失败", err);
    });
  ctx.body = data;
});

export default router;
